<!-- 安全教育 -->
<template>
	<view>
		<view class="p-3">
			<view class="bt-block">
				<bg-cell2 label="姓名" :value="$store.getters.name"></bg-cell2>
				<bg-cell2 label="性别">
					<template slot="value">
						<bg-label :options="dict.type.sys_user_sex" :value="$store.state.user.gender"></bg-label>
					</template>
				</bg-cell2>
				<bg-cell2 label="身份证号" :value="$store.state.user.idCardNo"></bg-cell2>
				<bg-cell2 :border="false" label="联系方式" :value="$store.state.user.phone"></bg-cell2>
			</view>
			<view class="bt-block mt-3">
				<bg-cell2 :border="false">
					<template slot="label">
						<view><text class="text-red">*</text> 选择项目</view>
					</template>
					<template slot="value">
						<bg-select :value.sync="projectId" :columns="projectList" key="project"></bg-select>
					</template>
				</bg-cell2>
			</view>
		</view>
		<view class="bt-footer">
			<bg-btn @click="confirm()">确定</bg-btn>
		</view>
	</view>
</template>

<script>
export default {
	dicts: ["sys_user_sex"],
	onLoad(options) {
		this.target = options.target
	},
	mounted() {
		this.$store.dispatch("types/getProjects").then(res => {
			this.projectList = res
		})
	},
	data() {
		return {
			projectList: [],
			projectId: '',
		}
	},
	methods: {
		confirm() {

			if (this.projectId) {
				// 如果地址是去安全培训考试 并且身份是高级管理员 则直接去安全培训的结果
				if (this.target == '/pages/enter/education/exam' && this.$auth.hasRoleOr(['super'])) {
					uni.navigateTo({
						//url: this.target + "?projectId=" + this.projectId
						url:'/pages/enter/education/viewStudyStatus' + "?projectId=" + this.projectId + "&type=super"
					})
					return
				} else {
					// 班组长既能学习也能查看手下员工的学习记录
					if (this.$auth.hasRoleOr(['team'])) {
						// 弹窗 查看学习记录还是去学习
						uni.showModal({
							title: '提示',
							content: '查看学习记录还是去学习？',
							cancelText: '去学习',
							confirmText: '查看学习记录',
							success: (res) => {
								if (res.confirm) {
									uni.navigateTo({
										url: `/pages/enter/education/viewStudyStatus` + "?projectId=" + this.projectId
									})
								} else if (res.cancel) {
									uni.navigateTo({
										url: this.target + "?projectId=" + this.projectId
									})

									return
								}
							}
						})
					}
					// 工人和班组长以外的身份
					if (!this.$auth.hasRoleOr(['team', 'worker'])) {
						uni.navigateTo({
							url: `/pages/enter/education/viewStudyStatus` + "?projectId=" + this.projectId
						})
						return
					}
					// 工人
					if (this.$auth.hasRoleOr(['worker'])) {
						uni.navigateTo({
							url: this.target + "?projectId=" + this.projectId
						})
						return
					}
				}


			} else {
				this.$modal.msg("请先选择项目")
			}

		}
	}
}
</script>

<style></style>
